package org.peterf.foxish.surface;

import org.peterf.foxish.engine.Engine;
import org.peterf.foxish.engine.setting.ScreenSetting;

import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.KeyEvent;

/**
 * A surface view for OpenGL 2.0 rendering.
 * 
 * @author peter
 * 
 */
public class SurfaceView extends GLSurfaceView {

    private Engine engine;

    /**
     * Create the surface with the initialized engine.
     * 
     * @param engine
     */
    public SurfaceView(Engine engine) {
        super(engine.getContext());
        this.engine = engine;
        setFocusable(true);
        setFocusableInTouchMode(true);
        setClickable(true);
        setEnabled(true);
        setEGLContextClientVersion(2);
        // TODO Exception check for the following instruction.
        setEGLConfigChooser(8, 8, 8, 8, 0, 0);
        // TODO Enable other kind of configures.
    }
    
    /**
     * 
     * @return The main engine.
     */
    public Engine getEngine() {
        return engine;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        ScreenSetting setting = engine.getScreenSetting();
        int size[] = setting.getMeasuredSize(widthMeasureSpec,
                heightMeasureSpec);
        setMeasuredDimension(size[0], size[1]);
    }

}
